package fr.teuteuf.runstickmanrun.map.tile;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;

import fr.teuteuf.runstickmanrun.Constants;

public class DamagingBoxTile extends Tile implements IDamagingTile {
	
	private World world;
	private Body body;
	private int damage;

	public DamagingBoxTile(int textureX, int textureY, int positionX, int positionY, World world, int damage) {
		super(textureX, textureY, positionX, positionY);
		this.world = world;
		this.damage = damage;
		
		BodyDef bodyDef = new BodyDef();
		bodyDef.position.set(new Vector2((positionX + Tile.TILE_SIZE/2) * Constants.WORLD_TO_BOX, (positionY + Tile.TILE_SIZE/2) * Constants.WORLD_TO_BOX));
		body = world.createBody(bodyDef);
		
		PolygonShape shape = new PolygonShape();
		shape.setAsBox(Tile.TILE_SIZE/2 * Constants.WORLD_TO_BOX, Tile.TILE_SIZE/2 * Constants.WORLD_TO_BOX);
		
		FixtureDef fixtureDef = new FixtureDef();
		fixtureDef.shape = shape;
		fixtureDef.isSensor = true;
		
		body.createFixture(fixtureDef);
		body.setUserData(this);
		shape.dispose();
	}
	
	@Override
	public void destroy() {
		super.destroy();
		world.destroyBody(body);
	}

	public int getDamage() {
		return damage;
	}

	public void setDamage(int damage) {
		this.damage = damage;
	}
}
